<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }}</div>
    <div class="table-operator">
      <!-- 搜索板块 -->
      <a-row class="row-item-search">
        <a-form class="search-form" :form="searchForm" layout="inline" @submit="handleSearch">
          <a-form-item label="订单号">
            <a-input v-decorator="['order_no']" placeholder="请输入订单号" />
          </a-form-item>
          <a-form-item label="注册时间">
            <a-range-picker format="YYYY-MM-DD" @change="handlePanelChange" />
          </a-form-item>
          <a-form-item class="search-btn">
            <a-button type="primary" icon="search" html-type="submit">搜索</a-button>
          </a-form-item>
        </a-form>
      </a-row>
    </div>
    <s-table
      ref="table"
      rowKey="id"
      :loading="isLoading"
      :columns="columns"
      :data="loadData"
      :rowSelection="rowSelection"
      :pageSize="15"
    >
    </s-table>
  </a-card>
</template>

<script>
import * as Api from '@/api/market/wine/dermemberProfitBill'
import { ContentHeader, STable } from '@/components'
import moment from 'moment'
// 表格表头
const columns = [
  {
    title: 'ID',
    dataIndex: 'bill_id',
  },
  {
    title: '订单号',
    dataIndex: 'order_no',
    scopedSlots: { customRender: 'order_no' },
  },
  {
    title: '用户ID',
    dataIndex: 'user_id',
    scopedSlots: { customRender: 'user_id' },
  },
  {
    title: '类型',
    dataIndex: 'type',
    scopedSlots: { customRender: 'type' },
  },
  {
    title: '变动前金额',
    dataIndex: 'front_amount',
    scopedSlots: { customRender: 'front_amount' },
  },
  {
    title: '变动后金额',
    dataIndex: 'after_amount',
    scopedSlots: { customRender: 'after_amount' },
  },
  {
    title: '浮动金额',
    dataIndex: 'float_amount',
    scopedSlots: { customRender: 'float_amount' },
  },
  {
    title: '变动描述',
    dataIndex: 'msg',
    scopedSlots: { customRender: 'msg' },
  },
  {
    title: '添加时间',
    dataIndex: 'create_time',
  },
]

export default {
  name: 'DermemberProfitBill',
  components: {
    ContentHeader,
    STable,
  },
  data() {
    return {
      // 当前表单元素
      searchForm: this.$form.createForm(this),
      // 商品分类列表
      categoryListTree: [],
      // 查询参数
      queryParam: {
        user_id: this.$route.query.user_id,
        limit: '15',
        betweenTime: [],
      },
      // 正在加载
      isLoading: false,
      // 表头
      columns,
      // 选择的元素
      selectedRowKeys: [],
      // 加载数据方法 必须为 Promise 对象
      loadData: (param) => {
        return Api.getList({ ...param, ...this.queryParam }).then((response) => {
          return response.data
        })
      },
    }
  },
  created() {
    // 默认的查询参数
  },
  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange,
      }
    },
  },
  methods: {
    moment,
    /**
     * 选中项发生变化时的回调
     */
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },

    //日期
    handlePanelChange(value, mode) {
      this.queryParam.betweenTime[0] =
        value[0] == undefined ? '' : moment(new Date(value[0]['_d'])).format('YYYY-MM-DD')
      this.queryParam.betweenTime[1] =
        value[1] == undefined ? '' : moment(new Date(value[1]['_d'])).format('YYYY-MM-DD')
    },

    // 确认搜索
    handleSearch(e) {
      e.preventDefault()
      this.searchForm.validateFields((error, values) => {
        if (!error) {
          this.queryParam = { ...this.queryParam, ...values }
          this.handleRefresh(true)
        }
      })
    },

    // 重置搜索表单
    handleReset() {
      this.searchForm.resetFields()
    },

    /**
     * 刷新列表
     * @param bool bool 强制刷新到第一页
     */
    handleRefresh(bool = false) {
      this.selectedRowKeys = []
      this.$refs.table.refresh(bool)
    },

    sortList(vars, orderType) {
      this.queryParam = { ...this.queryParam, ...orderType }
      this.handleRefresh(true)
    },
  },
}
</script>

<style scoped>
</style>